﻿#define _CRT_SECURE_NO_WARNINGS


#include<stdio.h>

#include<stdlib.h>


typedef struct node

{

	int data;

	struct node* next;

}QNode;


typedef struct 

{

QNode * front,*rear;

}LQueue;



LQueue* Init_LQueue();

void In_Queue(LQueue* q, int x);

int Empty_LQueue(LQueue* q);

int Out_LQueue(LQueue* q, int* x);

void PrintQueue(LQueue* q);



int main()

{

	LQueue* q;

	int x;

	int i;

	int a;

	q = Init_LQueue();

	printf("初始情况： ");

	for (i = 1; i <= 10; i++)

	{

		In_Queue(q, i);

	}

	PrintQueue(q);


	printf("输入入队元素： ");

	scanf("%d", &a);

	In_Queue(q, a);

	printf("入队后： ");

	PrintQueue(q);


	printf("出队一个元素后 ");

	Out_LQueue(q, &x);

	PrintQueue(q);

	printf("出队的元素值是：%d ", x);

	return 0;

}




LQueue* Init_LQueue()

{

	LQueue* q;

	QNode* p;

	q = (LQueue*)malloc(sizeof(LQueue));

	p = (QNode*)malloc(sizeof(QNode));

	p->next = NULL;

	q->front = p;

	q->rear = p;

	return q;

}


void In_Queue(LQueue* q, int x)

{

	QNode* p;

	p = (QNode*)malloc(sizeof(QNode));

	p->data = x;

	p->next = NULL;

	q->rear->next = p;

	q->rear = p;

}


int Empty_LQueue(LQueue* q)

{

	if (q->front == q->rear) return 1;

	else return 0;

}


int Out_LQueue(LQueue* q, int* x)

{

	QNode* p;

	if (Empty_LQueue(q))

	{

		printf("队空");

		return 0;

	}

	else

	{

		p = q->front->next;

		q->front->next = p->next;

		*x = p->data;

		free(p);

		if (q->front->next == NULL)

			q->rear = q->front;


		return 1;

	}

}


void PrintQueue(LQueue* q)

{

	QNode* p;

	p = q->front->next;

	while (p != NULL)

	{

		printf("%d ", p->data);

		p = p->next;

	}

	printf(" ");

}